//
//  OTDR_MainViewController.m
//  OTDR
//
//  Created by Liu on 2024/5/19.
//

#import "OTDR_MainViewController.h"
#import "OTDR_SocketConnectViewController.h"
#import "OTDR_LocalPageViewController.h"
#import "OTDR_SecondPageViewController.h"


@interface OTDR_MainViewController ()<NSURLSessionDelegate>
@property(nonatomic ,strong)NSURLSession *session;
@property(nonatomic ,strong)NSURLSessionTask *dataTask;
@end

@implementation OTDR_MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setNavTitleStr:@""];
    [self creatUI];
//    {0,0,0,-48,18,99,65,58};//
//    {58,65,99,18,-48,0,0,0};//
    
    char bytes[] = {-53,-54,-10,-97,-100,-108,71,64};
    long lv = 0;
    memcpy(&lv, &bytes, sizeof(long));
    double value = 0.0;
    memcpy(&value, &lv, sizeof(double));
    NSLog(@"%f",value);//47.1610
}



- (void )creatUI{
    UIButton *yuanchengBtn = [ViewCreate createButtonFrame:CGRectMake(SIZE(20), SCREEN_HEIGHT-SIZE(250), SCREEN_WIDTH-SIZE(40), SIZE(50)) title:[LanguageTool DPLocalizedString:@"otdryclj"] titleColor:RGB51 font:FONT(17) backgroundColor:kThemeColor];
    [self.view addSubview:yuanchengBtn];
    yuanchengBtn.layer.masksToBounds = YES;
    yuanchengBtn.layer.cornerRadius = SIZE(25);
    yuanchengBtn.tag = 10086;
    [yuanchengBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *localControlBtn = [ViewCreate createButtonFrame:CGRectMake(SIZE(20), SCREEN_HEIGHT-SIZE(190), SCREEN_WIDTH-SIZE(40), SIZE(50)) title:[LanguageTool DPLocalizedString:@"otdrbdlj"] titleColor:RGB51 font:FONT(17) backgroundColor:kThemeColor];
    [self.view addSubview:localControlBtn];
    localControlBtn.layer.masksToBounds = YES;
    localControlBtn.layer.cornerRadius = SIZE(25);
    localControlBtn.tag = 10087;
    [localControlBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void )btnAction:(UIButton *)sender{
    if (sender.tag == 10086) {
//        OTDR_SecondPageViewController *vc = [OTDR_SecondPageViewController new];
//        [self.navigationController pushViewController:vc animated:YES];
        
        OTDR_SocketConnectViewController *vc = [OTDR_SocketConnectViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else{
        OTDR_LocalPageViewController *vc = [OTDR_LocalPageViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

//
////获取图片流
//- (void )loadInputStream{
//    NSURL *url = [NSURL URLWithString:@"http:/***"];
//    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
//    [request setHTTPMethod:@"GET"];
//    self.session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]];
//    self.dataTask = [self.session dataTaskWithRequest:request];
//    [self.dataTask resume];
//}
//
////1.接收到服务器响应的时候调用
//- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask
//didReceiveResponse:(NSURLResponse *)response
// completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler{
//    NSLog(@"接收响应");
//    //必须告诉系统是否接收服务器返回的数据
//    //默认是completionHandler(NSURLSessionResponseAllow)
//    //可以再这边通过响应的statusCode来判断否接收服务器返回的数据
//    completionHandler(NSURLSessionResponseAllow);
//}
////2.接受到服务器返回数据的时候调用,可能被调用多次
//- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data{
//    NSLog(@"接收到数据");
//    
//}
////3.请求完成或者是失败的时候调用
//- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(nullable NSError *)error{
//    NSLog(@"请求完成或者是失败");
//    //在这边进行完整数据的解析，回调
//}
////4.将要缓存响应的时候调用（必须是默认会话模式，GET请求才可以）
//- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask willCacheResponse:(NSCachedURLResponse *)proposedResponse completionHandler:(void (^)(NSCachedURLResponse * _Nullable cachedResponse))completionHandler{
//    //可以在这边更改是否缓存，默认的话是completionHandler(proposedResponse)
//   
//    
//    
//    //不想缓存的话可以设置completionHandler(nil)
//    completionHandler(proposedResponse);
//}
@end
